﻿///***************************************************************
/// 시  스  템 : Updms.Com
/// 단위시스템 : COM
/// 계      층 : Presentation Layer
/// 프로그램명 : Com3014p
/// 파  일  명 : Com3014p.aspx.cs
/// 설      명 : 첨부파일내 이미지보기
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2013-06-17 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Web;
using System.Web.UI;

using SMFramework.Data;
using SMFramework.Utility;

using Base.Dac;
using Updms.Com.Exe;



namespace Updms.Com
{
	public partial class Com3014p : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		public static readonly string PID = "Com3014p";
		protected static string gs_no_image = "../Common/Images/picture_error.png";
		protected static bool gb_image_exist = false;

		#endregion

		#region Page_Load

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				CheckViewAuth();
			}
		}

		#endregion

		#region CheckViewAuth

		//인증검사
		private void CheckViewAuth()
		{
			using (AccessCheck access = new AccessCheck())
			{
				//접근권한 체크
				if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
				{
					Response.Redirect(URL_NO_AUTHORITY_REDIRECT_POPUP);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
				}
				else
				{
					SetImage();
				}
			}
		}

		#endregion

		#region SetImage

		//이미지 보기
		private void SetImage()
		{
			string ls_activity_cd = "";
			string ls_activity_id = "";
			int li_image_file_cnt = 0;

			DataPack lo_dp = new DataPack();
			DataSet lo_ds = new DataSet();

			if (Request.QueryString["activity_id"] != null && Request.QueryString["activity_cd"] != null)
			{
				if (StringUtil.HasLength(Request.QueryString["activity_id"].ToString()))
				{
					ls_activity_id = HttpUtility.UrlDecode(Request.QueryString["activity_id"].ToString());
				}
				if (StringUtil.HasLength(Request.QueryString["activity_cd"].ToString()))
				{
					ls_activity_cd = HttpUtility.UrlDecode(Request.QueryString["activity_cd"].ToString());
				}

				lo_dp.AddProperty("activity_id", typeof(int), ls_activity_id);
				lo_dp.AddProperty("activity_cd", typeof(string), ls_activity_cd);

				using (Com9010m_NT _Com9010m_NT = new Com9010m_NT())
				{
					lo_ds.Merge(_Com9010m_NT.GetFileInfoByActivityId(lo_dp));
				}

				if (DataSetUtil.CheckRowCount(lo_ds, "UPDMS_COM_FILE"))
				{
					string ls_image_urls = "";
					for (int i = 0; i < DataSetUtil.GetRowCount(lo_ds, "UPDMS_COM_FILE"); i++)
					{
						string ls_file_dir = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_FILE", i, "File_Dir");
						string ls_file_nm = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_FILE", i, "File_Nm");
						string ls_file_ext = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_FILE", i, "File_Ext");
						string ls_image_file = FILE_PATH_UPLOAD + "\\" + ls_file_dir + "\\" + ls_file_nm;

						//실제파일이 있는지 검사
						if (FileUtil.IsFileExist(ls_image_file))
						{
							//확장자가 이미지파일인지
							if (ValidationUtil.IsFileExtImg(ls_file_ext))
							{
								li_image_file_cnt++;
								ls_image_urls = ls_image_urls
									+ "<img src=\"" + FILE_PATH_UPLOAD_WEB_PATH + ls_file_dir + "/" + ls_file_nm + "\" border=\"0\" onclick=\"javascript:window.close()\" class=\"hand\" /><br />";
							}
						}
					}

					if (li_image_file_cnt > 0)
					{
						lbl_image_url.Text = ls_image_urls;
					}
					else
					{
						lbl_image_url.Text = "<br /><img src=\"" + gs_no_image + "\" border=\"0\" onclick=\"javascript:window.close()\" class=\"hand\" />";
					}
				}
				else
				{
					lbl_image_url.Text = "<br /><img src=\"" + gs_no_image + "\" border=\"0\" onclick=\"javascript:window.close()\" class=\"hand\" />";
				}
			}
		}

		#endregion

	}
}